#!/bin/bash

set -v on

# Stop logging services
service rsyslog stop
service auditd stop

# Remove old kernels
package-cleanup -y --oldkernels --count=1

# Clean yum cache
yum clean all

# shrink logspace
logrotate -f /etc/logrotate.conf

# Remove log files
rm -f /var/log/*-???????? /var/log/*.gz
rm -f /var/log/dmesg.old
rm -rf /var/log/anaconda

# Clear log file contents
cat /dev/null > /var/log/audit/audit.log 
cat /dev/null > /var/log/wtmp 
cat /dev/null > /var/log/lastlog 
cat /dev/null > /var/log/grubby

# Remove MAC and UUID
sed -i '/^\(HWADDR\|UUID\)=/d' /etc/sysconfig/network-scripts/ifcfg-e*

# Clear temp files
rm -rf /tmp/*
rm -rf /var/tmp/*

# Remove ssh host key
rm -f /etc/ssh/*key*

# Remove root shell historys
rm -f ~root/.bash_history
unset HISTFILE

# Remove root ssh historys
rm -rf ~root/.ssh/ 

# Remove install config file
rm -f ~root/anaconda-ks.cfg

# Remove machine id
cat /dev/null > /etc/machine-id

# Clear shell historys
history -c

# Reset system and shutdown
sys-unconfig